package jeu;

import javax.swing.*;

import wiimote.WiimoteLink;


import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

/**
 * Classe qui permet la connexion
 * 
 * @author jourdes
 */

@SuppressWarnings("serial")
public class MotdePasse implements KeyListener {
	private JTextField idd;
	private JFrame frame;
	public MotdePasse() {
		
		frame = new JFrame("Mot de passe");
		JPanel main = new JPanel(new GridLayout(3, 1));
		JPanel p1 = new JPanel();
		JPanel p2 = new JPanel();
		JPanel p3 = new JPanel();
		JPanel p4 = new JPanel();

		JLabel titre = new JLabel("Wii for U : Connexion");
		titre.setForeground(new Color(10, 0, 150));
		titre.setFont(new Font("Georgia", 1, 96));

		JLabel id = new JLabel("Identifiant : ");
		id.setForeground(Color.BLACK);
		id.setFont(new Font("Georgia", 1, 30));
		idd = new JTextField(30);
		idd.setFont(new Font("Georgia", 1, 30));

		JButton valider = new JButton("Valider");
		valider.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				verif();
			}
		});
		valider.setPreferredSize(new Dimension(200, 50));

		p1.add(titre);
		p2.add(id);
		p2.add(idd);
		p4.add(valider);
		frame.setFocusable(true);
		main.add(p1);
		main.add(p2);
		main.add(p4);
		frame.add(main);

		frame.addKeyListener(this);
		idd.addKeyListener(this);
		valider.addKeyListener(this);
		
		idd.setFocusable(true);

		frame.setVisible(true);
		idd.requestFocus();
		frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		frame.setExtendedState(JFrame.MAXIMIZED_BOTH);

	}

	@Override
	public void keyPressed(KeyEvent e) {
		if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
			System.exit(0);
		}

		if (e.getKeyCode() == KeyEvent.VK_ENTER) {
			verif();
		}
	}

	@Override
	public void keyReleased(KeyEvent arg0) {

	}

	@Override
	public void keyTyped(KeyEvent arg0) {

	}

	public void verif() {
			frame.dispose();
            try {
                new MenuJeu("Menu Principal", false,idd.getText());
            } catch (Exception e1) {
                e1.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
            }

		frame.setFocusable(true);

		idd.setFocusable(true);
		idd.requestFocus();
	}


}
